import {
  response,
  errorHandle,
  url
} from './response';

const getToken = () => {
  return wx.getStorageSync('auth');
}
/**
 * 查询配方调整引入方式
 * @param {*} data 
 * @param {*} successCallback 
 */
export const _list = (data, successCallback) => {
  wx.request({
    url: `${url}/recipeImportMethod/list`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 添加配方调整引入方式
 * @param {*} data 
 * @param {*} successCallback 
 */
export const _add = (data, successCallback) => {
  wx.request({
    url: `${url}/recipeImportMethod/add`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}

/**
 * 更改配方调整引入方式
 * @param {*} data 
 * @param {*} successCallback 
 */
export const _update = (data, successCallback) => {
  wx.request({
    url: `${url}/recipeImportMethod/update`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}

/**
 * 删除配方调整引入方式
 * @param {*} data 
 * @param {*} successCallback 
 */
export const _remove = (data, successCallback) => {
  wx.request({
    url: `${url}/recipeImportMethod/remove`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}